<?php

/**
 * CbItem form.
 *
 * @package    cnox
 * @subpackage form
 ** @author     Francisco Javier Amarilla Peralta
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class CbItemForm extends BaseCbItemForm
{
  public function configure()
  {
//      $this->useFields(array(
//          'id', 'title',
//          'cb_item_type_id', 'mname',
//          'icontent', 'icontent_type',
//          'iattachment', 'eliminado',
//          
//      ));
//      $this->setWidgets(array(
//          'icontent' => new isicsWidgetFormTinyMCE(array('tiny_options' => array('theme' => 'advanced')))
//      ));
      
    $this->setWidgets(array(
      'id'                  => new sfWidgetFormInputHidden(),
      'cb_item_type_id'     => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('CbItemType'), 'add_empty' => true)),
      'title'               => new sfWidgetFormInputText(),
      'mname'               => new sfWidgetFormInputText(),
      'icontent'            => new isicsWidgetFormTinyMCE(
              array(
                    'tiny_options' => array('width'=>'800px', 'height'=>'890px','theme' => 'advanced'))),
      'icontent_type'       => new sfWidgetFormInputText(),
      'iattachment'         => new
                  sfWidgetFormInputFileEditable(array(
                    'label' => 'Attachment',
                    'file_src' => sfConfig::get('sf_upload_dir').'/iattach/'.$this->getObject()->getIattachment(),
                    'is_image' => true,
                    'edit_mode' => !$this->isNew(),
                    'template' => '<div>%file%<br />%input%<br />%delete%
                    %delete_label%</div>',
                    )),
        
      'eliminado'           => new sfWidgetFormInputCheckbox(),
//      'created_at'          => new sfWidgetFormDateTime(),
//      'updated_at'          => new sfWidgetFormDateTime(),
//      'slug'                => new sfWidgetFormInputText(),
      'item_relations_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'CbItemRelation')),
    ));

    $this->setValidators(array(
      'id'                  => new sfValidatorChoice(array('choices' => array($this->getObject()->get('id')), 'empty_value' => $this->getObject()->get('id'), 'required' => false)),
      'cb_item_type_id'     => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('CbItemType'), 'required' => false)),
      'title'               => new sfValidatorString(array('max_length' => 250, 'required' => false)),
      'mname'               => new sfValidatorString(array('max_length' => 250, 'required' => false)),
      'icontent'            => new sfValidatorString(array('required' => false)),
      'icontent_type'       => new sfValidatorString(array('max_length' => 200, 'required' => false)),
      'iattachment'         => 
               new sfValidatorFile(
                       array('mime_types' => 'web_images',
                           'path'=>
                                sfConfig::get('sf_upload_dir').'/iattach/',
                           'required'=>false)
                      ),
      'eliminado'           => new sfValidatorBoolean(array('required' => false)),
//      'created_at'          => new sfValidatorDateTime(),
//      'updated_at'          => new sfValidatorDateTime(),
//      'slug'                => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'item_relations_list' => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'CbItemRelation', 'required' => false)),
    ));

    $this->validatorSchema->setPostValidator(
      new sfValidatorDoctrineUnique(array('model' => 'CbItem', 'column' => array('slug')))
    );

    $this->widgetSchema->setNameFormat('cb_item[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
  }
}
